<template>
  <div class="searchCategorie" v-if="categories">
    <div class="top">
      <div class="title">作品</div>
      <div
        class="all"
        @click="toSearchCategorieView({ category_id: 0, index: -1 })"
      >
        全部作品
      </div>
    </div>
    <div class="categories">
      <div
        class="categorie"
        v-for="(categorie, index) in categories"
        :key="categorie.id"
        @click="toSearchCategorieView({ category_id: categorie.id, index })"
      >
        <van-image
          width="160px"
          height="110px"
          radius="5px"
          lazy-load
          :src="categorie.cover"
        />
        <div class="title">{{ categorie.category_name }}</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: ["categories"],
  methods: {
    toSearchCategorieView({ category_id, index }) {
      this.$router.push({
        path: "/searchCategorie",
        query: { category_id, index },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.searchCategorie {
  margin-top: 30px;
  padding: 0 20px;

  .top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;

    .title {
      font-weight: bold;
      font-size: 18px;
    }

    .all {
      font-size: 13px;
      color: red;
    }
  }

  .categories {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;

    .categorie {
      margin-bottom: 15px;
      position: relative;

      :deep(.van-image) {
        display: block !important;
      }

      .title {
        color: white;
        font-size: 14px;
        font-weight: bold;
        position: absolute;
        left: 12px;
        top: 10px;
      }
    }
  }
}
</style>
